package cn.teacher.service.impl;

import cn.teacher.dao.TeacherDaoMapper;
import cn.teacher.pojo.Teacher;
import cn.teacher.pojo.dto.TeacherDTO;
import cn.teacher.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 毛苏宇
 * User: me
 * Date: 2020/6/24
 * Time: 22:20
 * Description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDaoMapper teacherDaoMapper;

    @Override
    public boolean remove(long userId) {
        return teacherDaoMapper.delete(userId) > 0 ? true : false;
    }

    @Override
    public TeacherDTO find(long userId) {
        return teacherDaoMapper.select(userId);
    }

    @Override
    public boolean add(Teacher teacher) {
        teacher.setUpdateTime(System.currentTimeMillis());
        return teacherDaoMapper.insert(teacher) > 0 ? true : false;
    }

    @Override
    public boolean modify(Teacher teacher) {
        teacher.setUpdateTime(System.currentTimeMillis());
        return teacherDaoMapper.update(teacher) > 0 ? true : false;
    }
}
